 #define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <unordered_map>
#include <unordered_set>
using namespace std;


class Solution1 {
public:
    bool containsDuplicate(vector<int>& nums) {
        unordered_set<int> hash;
        for (auto x : nums)
        {
            if (hash.count(x))
                return true;
            else
                hash.insert(x);
        }
        return false;
    }
};

class Solution2 {
public:
    bool containsNearbyDuplicate(vector<int>& nums, int k) {
        unordered_map<int, int> hash;
        for (int i = 0; i < nums.size(); i++)
        {
            if (hash.count(nums[i]))
            {
                if (i - hash[nums[i]] <= k) return true;
            }
            hash[nums[i]] = i;
        }
        return false;
    }
};